from django.http import HttpResponseRedirect
from django.shortcuts import render
from .models import History


# Create your views here.

def login_check(fn):
    def wrap(request, *args, **kwargs):
        if 'username' not in request.session or \
                'uid' not in request.session:

            return HttpResponseRedirect('/user/login')
        return fn(request, *args, **kwargs)

    return wrap


@login_check
def unprocessed_view(request):
    uid = request.session['uid']
    history = History.objects.filter(user_id =uid, status = 'unprocessed')
    return render(request, 'history/unprocessed.html',locals())


@login_check
def processing_view(request):
    uid = request.session['uid']
    history = History.objects.filter(user_id=uid, status='processing')
    return render(request, 'history/processing.html', locals())


@login_check
def processed_view(request):
    uid = request.session['uid']
    history = History.objects.filter(user_id=uid, status='processed')
    return render(request, 'history/processed.html', locals())
